<?php
//include Header
include("header.php");
?>

<?php
$_SESSION['klantnummer'];
if($_SESSION==null)
	{
				echo "<H1>U moet ingelogd zijn om uw winkelwagentje te kunnen zien.<H1>";
	}
else
{

$query1 = mysql_query(" 

	SELECT	productnaam, image, aantal, producten.productnummer as productnummer1, 
			(SELECT prijs 
			FROM productprijs 
			WHERE productnummer=productnummer1
			AND productprijs.datum >=ALL (	SELECT datum
											FROM productprijs
											WHERE productnummer=productnummer1)) as prijs, 
			(aantal*(SELECT prijs 
					FROM productprijs 
					WHERE productnummer=productnummer1
					AND productprijs.datum >=ALL 	(SELECT datum
													FROM productprijs
													WHERE productnummer=productnummer1))) AS Totaalprijs
	FROM mandje
	INNER JOIN producten
	ON mandje.productnummer=producten.productnummer
	INNER JOIN productprijs
	ON productprijs.productnummer=producten.productnummer
	WHERE klantnummer=" . $_SESSION['klantnummer'] . "
	GROUP BY producten.productnummer
	ORDER BY mandje.datum DESC"); //klantnummer wordt

$query2 = mysql_query(" SELECT SUM(Totaalprijs) as subtotaal
						FROM (SELECT	productnaam, image, aantal, producten.productnummer as productnummer1, 
										(SELECT prijs 
										FROM productprijs 
										WHERE productnummer=productnummer1
										AND productprijs.datum >=ALL (	SELECT datum
																		FROM productprijs
																		WHERE productnummer=productnummer1)) as prijs, 
										(aantal*(SELECT prijs 
												FROM productprijs 
												WHERE productnummer=productnummer1
												AND productprijs.datum >=ALL 	(SELECT datum
																				FROM productprijs
																				WHERE productnummer=productnummer1))) AS Totaalprijs
							FROM mandje
							INNER JOIN producten
							ON mandje.productnummer=producten.productnummer
							INNER JOIN productprijs
							ON productprijs.productnummer=producten.productnummer
							WHERE klantnummer=" . $_SESSION['klantnummer'] . "
							GROUP BY producten.productnummer) AS tussentabel"); //klantnummer wordt" . $_SESSION['klantnummer'] . "
							
while($row = mysql_fetch_array($query2))
	{
		$subtotaal=$row[subtotaal];
	}
													
														
echo "<div>";
echo 	"<table border=\"1\" id=\"productTable\" width=\"100%\">
		<thead>
			<tr>
				<th>Verwijder</th>
				<th>Aantal</th>
				<th>Afbeelding</th>
				<th>Product</th>
				<th>Stukprijs</th>
				<th width=\"150\">Totaalprijs</th>
				</tr>
		</thead>
		<tfoot>
			<tr>
			<td colspan=\"5\" rowspan=\"7\" </td>
			<td width=\"150\"><h3>Subtotaal</h3>excl. 19% BTW.</td>
			</tr>
			<tr>
			<td width=\"150\"><font color=red><h3>&euro; " .sprintf("%01.2f", ($subtotaal/100)) ."</h3></font></td>
			</tr>
			<tr>
				<td width=\"150\"><h3>+ 19% BTW.</h3></td>
			</tr>
			<tr>
			<td width=\"150\"><font color=red><h3>&euro; " .sprintf("%01.2f", ((($subtotaal/100)/100)*19)) ."</h3></font></td>
			</tr>
			<tr>
				<td width=\"150\"><h3>Totaalprijs</h3></td>
			</tr>
			<tr>
			<td width=\"150\"><font color=red><h3>&euro; " .sprintf("%01.2f", (((($subtotaal/100)/100)*19))+($subtotaal/100)) ."</h3></font></td>
			</tr>
			<tr>
			<form name=\"mandje\" action=\"IDEAL.php\" method=\"post\">
				<input type=\"hidden\" name=\"bedrag\" value=\"" .sprintf("%01.2f", (((($subtotaal/100)/100)*19))+($subtotaal/100)) . "\" />
				<input type=\"hidden\" name=\"klantnummer\" value=\"" . $_SESSION['klantnummer'] . "\" />
				<td width=\"150\" BGCOLOR=\"9593C2\"><A href=\"javascript:document.mandje.submit()\"><IMG SRC=\"/images/button_afrekenen.gif\"></A></td>
			</form>
			</tr>
		<tfoot>
		<tbody>";
while($row = mysql_fetch_array($query1))
  {
  echo "<tr>
			<td>
			<form action=\"deleteFromMandje.php\" method=\"post\"> 
			<input type=\"hidden\" name=\"klantnummer\" value=".$_SESSION['klantnummer']." />
			<input type=\"hidden\" name=\"productnummer\" value=". $row['productnummer1'] ." />
			<input type=\"image\" src=\"/images/remove.jpg\"> 
			</form> 
			</td>
			<td>
			<form action=\"process.php\" method=\"post\"> 
			<input size=\"1\" type=\"text\" value=\"".$row['aantal']."\" name=\"aantal\">
			<input type=\"hidden\" name=\"klantnummer\" value=".$_SESSION['klantnummer']." />
			<input type=\"hidden\" name=\"productnummer\" value=". $row['productnummer1'] ." />
			<input type=\"image\" src=\"/images/change.jpg\"> 
			</form> 
			</td>
			<td>
				<a href=\"product.php?id=" . $row['productnummer1'] . "\"><img src=\"/images/producten/thumb_" . $row[image] . "\" /></a>
			</td>
			<td>
				<a href=\"product.php?id=" . $row['productnummer1'] . "\">" . $row['productnaam'] . "</a>
			</td>
			<td>
				&euro;" .sprintf("%01.2f", ($row[prijs]/100)) . "
			</td>
			<td width=\"150\">
				&euro;" .sprintf("%01.2f", ($row[Totaalprijs]/100)) . "
			</td>
		</tr>";
  }
 
echo "</table>";
echo "</div>";
}
?>

<?php
//include footer
include("footer.php");
//nieuwe text!!!
?>
